import React, { Component } from 'react';
import { BrowserRouter as Router, Route, NavLink } from 'react-router-dom'
import vipmessage from '../css/Vipmessage.module.css'
import { Input, Icon, Button, Upload, message } from 'antd';


function getBase64(img, callback) {
    const reader = new FileReader();
    reader.addEventListener('load', () => callback(reader.result));
    reader.readAsDataURL(img);
}

function beforeUpload(file) {
    const isJPG = file.type === 'image/jpeg';
    if (!isJPG) {
        message.error('You can only upload JPG file!');
    }
    const isLt2M = file.size / 1024 / 1024 < 2;
    if (!isLt2M) {
        message.error('Image must smaller than 2MB!');
    }
    return isJPG && isLt2M;
}




export default class Vipmessage extends Component {
    constructor(props) {
        super(props)

        this.state = {
            loading: false,
        };
    }

    handleChange = info => {
        if (info.file.status === 'uploading') {
            this.setState({ loading: true });
            return;
        }
        if (info.file.status === 'done') {
            // Get this url from response in real world.
            getBase64(info.file.originFileObj, imageUrl =>
                this.setState({
                    imageUrl,
                    loading: false,
                }),
            );
        }
    };

    render() {

        const uploadButton = (
            <div>
                <Icon type={this.state.loading ? 'loading' : 'plus'} />
            </div>
        );
        const { imageUrl } = this.state;


        return (
            <div>
                <div className={vipmessage.main}>
                    <div className={vipmessage.maincenter}>
                        <div className={vipmessage.maincenterleft}>
                            <h2>会员中心</h2>
                            <span className={vipmessage.solid}></span>
                            <NavLink onClick={this.pm.bind(this)}><Icon type="user-delete" />个人信息</NavLink>
                            <span className={vipmessage.solid}></span>
                            <NavLink onClick={this.xp.bind(this)}><Icon type="lock" />修改密码</NavLink>
                            <span className={vipmessage.solid}></span>
                        </div>
                        <div className={vipmessage.maincenterright}>
                            <div className={vipmessage.rightperson} ref="pers">
                                <h2>个人信息</h2>
                                <span className={vipmessage.solid}></span>
                                <div>
                                    <ul>
                                        <li>
                                            <b>*昵称：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <b>邮箱：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <b>*手机号码：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <b>真实姓名：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <b>性别：</b><input type="radio" name="mal" />男<input type="radio" name="mal" />女
                                        </li>
                                        <li>
                                            <b>出生日期：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <b>QQ账号：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <b>个人介绍：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <Button size="large">
                                                保存
                                            </Button>
                                        </li>
                                    </ul>
                                </div>
                                <div >
                                    <Upload
                                        name="avatar"
                                        listType="picture-card"
                                        className="avatar-uploader"
                                        showUploadList={false}
                                        action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
                                        beforeUpload={beforeUpload}
                                        onChange={this.handleChange}
                                    >
                                        {imageUrl ? <img src={imageUrl} alt="avatar" /> : uploadButton}
                                    </Upload>
                                </div>
                            </div>
                            <div className={vipmessage.rightpassword} ref="pass">
                                <div className={vipmessage.float}></div>
                                <h2>修改密码</h2>
                                <span className={vipmessage.solid}></span>
                                <div>
                                    <ul>
                                        <li>
                                            <b>用户名:<span>111</span></b>
                                        </li>
                                        <li>
                                            <b>旧密码：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <b>新密码：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <b>确认新密码：</b><Input placeholder="" />
                                        </li>
                                        <li>
                                            <Button size="large">保存</Button>
                                            <Button size="large" onClick={this.pm.bind(this)}>取消</Button>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        )
    }
    pm(){
        this.refs.pers.style.display='block'
        this.refs.pass.style.display='none'
    }
    xp(){
        this.refs.pers.style.display='none'
        this.refs.pass.style.display='block'
    }
}